home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / manchest.lha / MANCHESTER / usenet / st80_pre4 / pretty-print / exampleCommands.st < prev    next >
Text File  |  1993-07-24  |  25KB  |  1,257 lines

  1. "\TeXCommand
  2. \startClassDef{Boiler}{Components}
  3. \setVersion{1:48 on Oct  4, 1991}
  4. \setHierarchy{{Components}{TestHeating}{Object}}
  5. \endClassDef
  6. "!
  7.  
  8.  
  9. Components subclass: #Boiler
  10.   instanceVariableNames: 
  11.     'oilValve  ignitor  tempSensor  oilFlowSensor  
  12.      combustionSensor  internalModels  '
  13.   classVariableNames: ''
  14.   poolDictionaries: ''.
  15.  
  16. "\TeXCommand
  17. \startClassSection{Comment}
  18. "!
  19.  
  20.  
  21. Boiler
  22.   comment:
  23. '
  24. This is a Furnace Boiler. It is composed of a number
  25. of small parts:
  26.    oilValve           controls whether oil is flowing
  27.    ignitor            ignites the boiler
  28.  
  29.    tempSensor         monitors the temperature in the boiler
  30.  
  31.    oilFlowSensor
  32.    combustionSensor   detect faults
  33.  
  34. all of the above are types of Informers, as are most
  35. of this system.
  36.  
  37. Also see diagram: BoilerDiagram.eps
  38. '. !
  39.  
  40. "\TeXCommand
  41. \diagram{BoilerDiagram.eps}
  42. "!
  43.  
  44. "\TeXCommand
  45. \startClassSection{Summary}
  46. "!
  47.  
  48. "
  49. ************* Class Methods Summary ************
  50.  
  51. ----Public----
  52. new
  53.  
  54.  
  55. *********** Instance Methods Summary ***********
  56.  
  57. ----Public----
  58. faultExists              Do my sensors presently detect a fault   
  59. initialize
  60. release
  61. resetFault               Try to reset the fault yourself 
  62. turnOff
  63. turnOn
  64.  
  65.   Dependency  
  66. update: who
  67. update: who with: detail
  68.  
  69.   Widget  
  70. initWindowSize           Tell the topWidget what size to open to 
  71. modelReleased: who
  72.      The top Pane lost a model for one of its subPanes.
  73.      The whole window should close. 
  74.  
  75. openView                 create a boiler interface      
  76.  
  77. ----Limited----
  78. combustionSensor         My combustionSensor 
  79. ignitor                  my ignitor 
  80. oilFlowSensor
  81. oilValve
  82. tempSensor               My temp sensor 
  83.  
  84.  
  85. ***************** End Summary ******************
  86. "!
  87.  
  88.  
  89.  
  90. !Boiler class methods !
  91.  
  92. new
  93.         <<Public>>
  94.  
  95.     ^super new initialize! !
  96.  
  97.  
  98. !Boiler methods !
  99.  
  100. combustionSensor
  101.         <<Limited>>
  102.     "My combustionSensor"
  103.     ^combustionSensor!
  104.  
  105. faultExists
  106.         <<Public>>
  107.     "Do my sensors presently detect a fault  "
  108.  
  109.     ^(oilFlowSensor value) | (combustionSensor value)!
  110.  
  111. ignitor
  112.         <<Limited>>
  113.     "my ignitor"
  114.  
  115.     ^ignitor!
  116.  
  117. initialize
  118.         <<Public>>
  119.     | sim  |
  120.  
  121.     oilValve := Valve new.
  122.     oilValve addDependent: self.
  123.  
  124.     ignitor := Ignitor new.
  125.  
  126.     oilFlowSensor := BooleanInformer new.
  127.     oilFlowSensor addDependent: self.
  128.  
  129.     combustionSensor := BooleanInformer new.
  130.     combustionSensor addDependent: self.
  131.  
  132.     tempSensor := IntervalInformer new.
  133.     tempSensor
  134.         min: 60 max: 300 precision: 2.
  135.     tempSensor addDependent: self.
  136.  
  137.  
  138.     sim := BoilerSim new.
  139.     sim initChange: tempSensor on: oilValve
  140.         plus: 15 minus: 10 per: #fiveSecondEvent
  141.         atTemp: 220.
  142.  
  143.     internalModels := OrderedCollection with: sim.!
  144.  
  145. initWindowSize
  146.         <<Public>><<Widget>>
  147.     "Tell the topWidget what size to open to"
  148.     | listLineHeight halfLineHeight |
  149.  
  150.     listLineHeight := Font menuFont height + 12.
  151.     halfLineHeight := Font menuFont height + 6.
  152.  
  153.     ^200@((6*listLineHeight) + (halfLineHeight*0) - 2)!
  154.  
  155. modelReleased: who
  156.         <<Public>><<Widget>>
  157.     "The top Pane lost a model for one of its subPanes.
  158.      The whole window should close."
  159.  
  160.     ^true!
  161.  
  162. oilFlowSensor
  163.         <<Limited>>
  164.     ^oilFlowSensor!
  165.  
  166. oilValve
  167.         <<Limited>>
  168.     ^oilValve!
  169.  
  170. openView
  171.         <<Public>><<Widget>>
  172.     "create a boiler interface     "
  173.  
  174.     | listLineHeight aWidget aView
  175.       faultStatus1Model faultStatus2Model ignitorStatusModel valveStatusModel
  176.       topWidget min max
  177.       halfLineHeight
  178.     |
  179.  
  180.  
  181.     CursorManager execute change.
  182.  
  183.     listLineHeight := Font menuFont height + 12.
  184.     halfLineHeight := Font menuFont height + 6.
  185.  
  186.  
  187.     topWidget := WTopWidget new
  188.         "model: nil;"
  189.         owner: self;
  190.         label: 'Boiler';
  191.         yourself.
  192.  
  193.     topWidget := topWidget.
  194.  
  195.     topWidget  view minimumSize: 300 @ 200.
  196.     topWidget  view whiteOnRedraw: true.
  197.     topWidget  view windowType: Window noGrowDocProc.
  198.  
  199.  
  200.  
  201.  
  202.     topWidget addSubWidget:
  203.         ((aWidget := WLinearView newWidget)
  204.             model: tempSensor;
  205.             owner: self).
  206.     aView := aWidget view.
  207.  
  208.  
  209.     min := tempSensor min. max := tempSensor max.
  210.  
  211.     aView
  212.             drawBorder: #thicktLine;
  213.             framingBlock: [:box|
  214.                 box origin + (0 @ (listLineHeight * 2))
  215.                     extent:
  216.                 box width @ (listLineHeight * 2 + halfLineHeight)];
  217.             initLowReading:  min
  218.                 highReading:  max
  219. "
  220.                 startDegree: 90
  221.                 rangeDegree: 360
  222. "
  223.                 tickMarks: (( min to:  max by: 30) collect:
  224.                     [:item | ((item - min) \\ 60 == 0) ifTrue: [
  225.                         item printString] ifFalse: ['']
  226.                 ])
  227.                 subTicks: 2";
  228.             extraBorder: 10".
  229.  
  230.  
  231.  
  232.     (valveStatusModel := CalcValueInformer new)
  233.         valueBlock: [:model |
  234.             model value ifTrue: ['Oil Flowing'] ifFalse: ['Oil Valve  
  235. Closed']];
  236.         model: oilValve.
  237.  
  238.     (ignitorStatusModel := CalcValueInformer new)
  239.         valueBlock: [:model |
  240.             model value ifTrue: ['Ignite'] ifFalse: ['Ignitor Off']];
  241.         model: ignitor.
  242.  
  243.     (faultStatus1Model := CalcValueInformer new)
  244.         valueBlock: [:model |
  245.             model value ifTrue: ['Comb. Fault'] ifFalse: ['Combustion']];
  246.         model: combustionSensor.
  247.  
  248.     (faultStatus2Model := CalcValueInformer new)
  249.         valueBlock: [:model |
  250.             model value ifTrue: ['Oil Fault'] ifFalse: ['Oil Flow']];
  251.         model: oilFlowSensor.
  252.  
  253.  
  254.     topWidget addSubWidget:
  255.         ((aWidget := WStatusWidget new)
  256.             setNilDecodeBlock;
  257.             owner: self).
  258.     aView := aWidget view.
  259.  
  260.     aView
  261.             label: 'Boiler Temp ( F)';
  262.             drawBorder: #thickbLine;
  263.             framingBlock: [:box|
  264.                 box origin + (0 @ ((listLineHeight * 4)))
  265.                     extent:
  266.                 box width @ halfLineHeight];
  267.             yourself.
  268.  
  269.  
  270.     topWidget addSubWidget:
  271.         ((aWidget := WStatusWidget new)
  272.             modelText: valveStatusModel boolean: oilValve;
  273.             owner: self).
  274.     aView := aWidget view.
  275.  
  276.     aView
  277.             drawBorder: #bLine;
  278.             framingBlock: [:box|
  279.                 box origin + (0 @ 0 )
  280.                     extent:
  281.                 box width @ listLineHeight];
  282.             yourself.
  283.  
  284.     topWidget addSubWidget:
  285.         ((aWidget := WStatusWidget new)
  286.             modelText: ignitorStatusModel boolean: ignitor;
  287.             owner: self).
  288.     aView := aWidget view.
  289.     aView
  290.             drawBorder: #bLine;
  291.             framingBlock: [:box|
  292.                 box origin + (0 @ (listLineHeight * 1))
  293.                     extent:
  294.                 box width @ listLineHeight];
  295.             yourself.
  296.  
  297.     topWidget addSubWidget:
  298.         ((aWidget := WStatusWidget new)
  299.             modelText: faultStatus1Model boolean: combustionSensor;
  300.             owner: self).
  301.     aView := aWidget view.
  302.     aView
  303.             drawBorder: #double;
  304.             framingBlock: [:box|
  305.                 box origin + (0 @ (box height  - (listLineHeight * 1) - 2))
  306.                     extent:
  307.                 box width // 2 @ listLineHeight];
  308.             yourself.
  309.  
  310.     topWidget addSubWidget:
  311.         ((aWidget := WStatusWidget new)
  312.             modelText: faultStatus2Model boolean: oilFlowSensor;
  313.             owner: self).
  314.     aView := aWidget view.
  315.     aView
  316.             drawBorder: #double;
  317.             framingBlock: [:box|
  318.                 box origin + (box width // 2 @ (box height  - (listLineHeight  
  319. * 1) - 2))
  320.                     extent:
  321.                 box width // 2 @ listLineHeight];
  322.             yourself.
  323.  
  324.     internalModels add: ignitorStatusModel;
  325.                    add: valveStatusModel;
  326.                    add: faultStatus1Model;
  327.                    add: faultStatus2Model.
  328.  
  329. "                   add: topWidget"
  330.  
  331.     topWidget open.
  332.     topWidget addWindow.!
  333.  
  334. release
  335.         <<Public>>
  336.  
  337.     super release.
  338.  
  339.     internalModels isNil ifFalse: [
  340.         internalModels do: [:each |
  341.             each releaseFirst: self.
  342.         ].
  343.     ].
  344.     internalModels := nil.
  345.  
  346.     oilValve releaseFirst: self.
  347.     oilValve := nil.
  348.  
  349.     ignitor releaseFirst: self.
  350.     ignitor := nil.
  351.  
  352.     oilFlowSensor releaseFirst: self.
  353.     oilFlowSensor := nil.
  354.  
  355.     combustionSensor releaseFirst: self.
  356.     combustionSensor := nil.
  357.  
  358.     tempSensor releaseFirst: self.
  359.     tempSensor := nil.!
  360.  
  361. resetFault
  362.         <<Public>>
  363.     "Try to reset the fault yourself"
  364.  
  365.     combustionSensor toFalse.!
  366.  
  367. tempSensor
  368.         <<Limited>>
  369.     "My temp sensor"
  370.     ^tempSensor!
  371.  
  372. turnOff
  373.         <<Public>>
  374.  
  375.     oilValve toFalse.!
  376.  
  377. turnOn
  378.         <<Public>>
  379.  
  380.     self faultExists ifTrue: [^false].
  381.  
  382.     oilValve open.
  383.  
  384.     "wait for the oilValve to open"
  385.  
  386.     [self faultExists or: [oilValve value]] whileFalse: [].
  387.  
  388.     self faultExists ifFalse: [
  389.         ignitor ignite.
  390.         ^true
  391.     ].
  392.     ^false!
  393.  
  394. update: who
  395.         <<Public>><<Dependency>>
  396.  
  397.  
  398.     ((who == oilFlowSensor | (who == combustionSensor))
  399.       and: [self faultExists]) ifTrue: [
  400.         ^self changedDetail: #fault
  401.     ].
  402.  
  403.         "Remind people a fault condition exists"
  404.     self faultExists ifTrue: [self changedDetail: #fault].
  405.  
  406.  
  407.  
  408.     who == tempSensor ifTrue: [
  409.         tempSensor value >= 150 ifTrue: [
  410.             ^self changedDetail: #atTemperature
  411.         ].
  412.     ].!
  413.  
  414. update: who with: detail
  415.         <<Public>><<Dependency>>
  416.  
  417.     detail == #release ifTrue: [
  418.         self release.
  419.         ^self
  420.     ].
  421.  
  422.     self update: who.! !
  423.  
  424.  
  425. "\TeXCommand
  426. \startClassDef{Furnace}{TestHeating}
  427. \setVersion{1:48 on Oct  4, 1991}
  428. \setHierarchy{{TestHeating}{Object}}
  429. \endClassDef
  430. "!
  431.  
  432.  
  433. TestHeating subclass: #Furnace
  434.   instanceVariableNames: 
  435.     'heatingSystem  state  boiler  blower  startCoolingTime  
  436.      activateDesired  internalModels  '
  437.   classVariableNames: ''
  438.   poolDictionaries: ''.
  439.  
  440. "\TeXCommand
  441. \startClassSection{Comment}
  442. "!
  443.  
  444.  
  445. Furnace
  446.   comment:
  447. '
  448.  
  449. A furnace is composed of:
  450.     Boiler
  451.     Blower
  452.  
  453. Internal values:
  454.     startCoolingTime
  455.     activateDesired
  456.  
  457. The object <state> is a Furnace state and
  458. handles validating state moves (basically
  459. it just prevents missspellings.)
  460. '
  461. .
  462.  !
  463. "\TeXCommand
  464. \startClassSection{Summary}
  465. "!
  466.  
  467.  
  468. "
  469. ************* Class Methods Summary ************
  470.  
  471. ----Public----
  472. newForSystem: aSystem
  473.  
  474.  
  475. *********** Instance Methods Summary ***********
  476.  
  477. ----Public----
  478. activate                 Turn on the furnace if you can 
  479. deactivate
  480. faultExists
  481. isOn
  482. release
  483. resetFault               Try to reset the fault yourself 
  484. shutDown
  485. startUp                  Don't need to do anything to start up
  486. state
  487.  
  488.   Dependency  
  489. update: who
  490. update: who with: detail
  491.  
  492.   Widget  
  493. initWindowSize           Tell the topWidget what size to open to 
  494. initWindowSize: who      Tell the topWidget what size to open to 
  495. openAllViews             Bring up a window on the activate switch 
  496. openView                 Bring up a window on the activate switch 
  497.  
  498. ----Limited----
  499. blower
  500. boiler
  501. clock
  502.  
  503. ----Private----
  504. activated               We are now on 
  505. initForSystem: aSystem
  506. stable
  507.      The stable state of the system, with a furnace ready
  508.      to run 
  509.  
  510. startBlower
  511. startBoiler
  512. startCooling
  513. stopBlower
  514. stopBoiler
  515.  
  516.  
  517. ***************** End Summary ******************
  518. "!
  519.  
  520.  
  521.  
  522. !Furnace class methods !
  523.  
  524. newForSystem: aSystem
  525.         <<Public>>
  526.  
  527.     ^super new initForSystem: aSystem.! !
  528.  
  529.  
  530. !Furnace methods !
  531.  
  532. activate
  533.         <<Public>>
  534.     "Turn on the furnace if you can"
  535.  
  536.     self faultExists ifTrue: [
  537.         ^false
  538.     ].
  539.  
  540.     (state isStopping) ifTrue: [
  541.         activateDesired := true.
  542.         state isStable ifTrue: [^self stable]. "Update ourselves"
  543.     ].!
  544.  
  545. activated
  546.         <<Private>>
  547.    "We are now on"
  548.  
  549.     state activated.
  550.     self changedDetail: #activated.!
  551.  
  552. blower
  553.         <<Limited>>
  554.  
  555.     ^blower!
  556.  
  557. boiler
  558.         <<Limited>>
  559.  
  560.     ^boiler!
  561.  
  562. clock
  563.         <<Limited>>
  564.  
  565.     heatingSystem isNil ifTrue: [^C].
  566.     ^heatingSystem clock!
  567.  
  568. deactivate
  569.         <<Public>>
  570.  
  571.     activateDesired := false.
  572.  
  573.     state isStartingBlower ifTrue: [
  574.         ^self stopBlower
  575.     ].
  576.     (state isStartingBoiler) | (state isActivated) ifTrue: [
  577.         ^self stopBoiler
  578.     ].!
  579.  
  580. faultExists
  581.         <<Public>>
  582.  
  583.     ^boiler faultExists!
  584.  
  585. initForSystem: aSystem
  586.         <<Private>>
  587.  
  588.     heatingSystem := aSystem.
  589.  
  590.     state := FurnaceState new.
  591.     state addDependent: self.
  592.     state stable.
  593.  
  594.  
  595.     activateDesired := false.
  596.  
  597.     blower := Blower new.
  598.     blower addDependent: self.
  599.  
  600.  
  601.     boiler := Boiler new.
  602.     boiler addDependent: self.
  603.  
  604.     internalModels := OrderedCollection new.
  605.  
  606.     self clock addDependent: self.!
  607.  
  608. initWindowSize
  609.         <<Public>><<Widget>>
  610.     "Tell the topWidget what size to open to"
  611.     | listLineHeight halfLineHeight |
  612.     listLineHeight := Font menuFont height + 12.
  613.  
  614.     ^200@(listLineHeight)!
  615.  
  616. initWindowSize: who
  617.         <<Public>><<Widget>>
  618.    "Tell the topWidget what size to open to"
  619.  
  620.     | listLineHeight halfLineHeight |
  621.     listLineHeight := Font menuFont height + 12.
  622.  
  623.     ^150@(listLineHeight)!
  624.  
  625. isOn
  626.         <<Public>>
  627.  
  628.     ^state isActivated!
  629.  
  630. openAllViews
  631.         <<Public>><<Widget>>
  632.     "Bring up a window on the activate switch"
  633.  
  634.  
  635.     boiler openView.
  636.     blower openView.
  637.     self openView.!
  638.  
  639. openView
  640.         <<Public>><<Widget>>
  641.     "Bring up a window on the activate switch"
  642.     |simple topWidget statusModel statusModel2|
  643.  
  644.  
  645.     (statusModel := CalcValueInformer new)
  646.         valueBlock: [:model |
  647.             (model isStable ifFalse: [model state printString]
  648.              ifTrue: ['Deactivated'])];
  649.         model: state.
  650.  
  651.     (statusModel2 := CalcValueInformer new)
  652.         valueBlock: [:model |
  653.             (model isActivated)];
  654.         model: state.
  655.  
  656.     simple := (SimpleWidgetWindow new createStatusOnText: statusModel boolean:  
  657. statusModel2).
  658.     simple
  659.         owner: self.
  660.  
  661.     topWidget := simple topWidget.
  662.  
  663.     topWidget label: 'Furnace'.
  664.  
  665.  
  666.     topWidget view windowType: Window noGrowDocProc.
  667.  
  668.     "topWidget view closeable: false."
  669.  
  670.     internalModels add: statusModel;
  671.                    add: statusModel2.
  672.  
  673.  
  674.     topWidget open; addWindow.!
  675.  
  676. release
  677.         <<Public>>
  678.  
  679.     super release.
  680.  
  681.     internalModels isNil ifFalse: [
  682.         internalModels do: [:each |
  683.             each releaseFirst: self.
  684.         ].
  685.     ].
  686.     internalModels := nil.
  687.  
  688.     self clock release: self.
  689.  
  690.  
  691.     state releaseFirst: self.
  692.     state := nil.
  693.  
  694.     boiler releaseFirst: self.
  695.     boiler := nil.
  696.  
  697.     blower releaseFirst: self.
  698.     blower := nil.
  699.  
  700.     heatingSystem := nil.!
  701.  
  702. resetFault
  703.         <<Public>>
  704.     "Try to reset the fault yourself"
  705.  
  706.  
  707.     boiler resetFault!
  708.  
  709. shutDown
  710.         <<Public>>
  711.  
  712.     self deactivate.!
  713.  
  714. stable
  715.         <<Private>>
  716.     "The stable state of the system, with a furnace ready
  717.      to run"
  718.  
  719.     activateDesired ifTrue: [
  720.         self faultExists ifFalse: [
  721.             activateDesired := false.
  722.             ^self startBlower
  723.         ].
  724.     ].
  725.     ^state stable.!
  726.  
  727. startBlower
  728.         <<Private>>
  729.  
  730.     state startingBlower.
  731.     ^blower turnOn!
  732.  
  733. startBoiler
  734.         <<Private>>
  735.  
  736.     state startingBoiler.
  737.     boiler turnOn ifFalse: [
  738.         ^self stopBoiler
  739.     ].!
  740.  
  741. startCooling
  742.         <<Private>>
  743.  
  744.     startCoolingTime := self clock currentTime.
  745.     ^state cooling!
  746.  
  747. startUp
  748.         <<Public>>
  749.     "Don't need to do anything to start up"!
  750.  
  751. state
  752.         <<Public>>
  753.  
  754.     ^state value!
  755.  
  756. stopBlower
  757.         <<Private>>
  758.  
  759.     state stoppingBlower.
  760.     ^blower turnOff.!
  761.  
  762. stopBoiler
  763.         <<Private>>
  764.  
  765.     state stoppingBoiler1.
  766.     ^boiler turnOff.!
  767.  
  768. update: who
  769.         <<Public>><<Dependency>>!
  770.  
  771. update: who with: detail
  772.         <<Public>><<Dependency>>
  773.  
  774.     detail == #release ifTrue: [
  775.         self release.
  776.         ^self
  777.     ].
  778.  
  779.  
  780.     (detail ~~ #fiveSecondEvent) & (detail ~~#secondEvent) ifTrue: [
  781. "
  782.        Transcript nextPutAll: detail printString,' by: ', who printString;cr.
  783. "
  784.     ].
  785.  
  786.  
  787.  
  788.     detail == #fault ifTrue: [
  789.         (state isStartingBoiler) | (state isActivated)
  790.                 ifTrue: [
  791.             self stopBoiler.
  792.         ].
  793.         (state isStartingBlower) ifTrue: [
  794.             self stopBlower.
  795.         ].
  796.         self changedDetail: #fault.
  797.         ^self
  798.     ].
  799.  
  800.         "Remind people a fault condition exists"
  801.     self faultExists ifTrue: [self changedDetail: #fault].
  802.  
  803.     detail == #atSpeed ifTrue: [
  804.         state isStartingBlower ifTrue: [
  805.             ^self startBoiler
  806.         ].
  807.         ^self
  808.     ].
  809.  
  810.     detail == #atTemperature ifTrue: [
  811.         Transcript nextPutAll: detail printString,' by: ', who printString;cr.
  812.         state isStartingBoiler ifTrue: [
  813.             ^self activated
  814.         ].
  815.         ^self
  816.     ].
  817.  
  818.  
  819.     detail == #fiveSecondEvent ifTrue: [
  820.         (state isCooling) ifTrue: [
  821.             (self clock currentTime subtractTime: startCoolingTime)
  822.                     minutes < 1 ifFalse: [
  823.                 ^self stable
  824.             ].
  825.         ].
  826.         (state isStoppingBoiler1) ifTrue: [
  827.             ^state stoppingBoiler2
  828.         ].
  829.         (state isStoppingBoiler2) ifTrue: [
  830.             ^self stopBlower
  831.         ].
  832.         (state isStoppingBlower) ifTrue: [
  833.             ^self startCooling
  834.         ].
  835.         (state isStable) ifTrue: [
  836.             self stable
  837.         ]
  838.     ].
  839.  
  840.     self update: who.! !
  841. "\TeXCommand
  842. \startClassDef{Blower}{Components}
  843. \setVersion{1:48 on Oct  4, 1991}
  844. \setHierarchy{{Components}{TestHeating}{Object}}
  845. \endClassDef
  846. "!
  847.  
  848.  
  849. Components subclass: #Blower
  850.   instanceVariableNames: 
  851.     'speed on internalModels '
  852.   classVariableNames: ''
  853.   poolDictionaries: ''.
  854.  
  855. "\TeXCommand
  856. \startClassSection{Comment}
  857. "!
  858.  
  859.  
  860. Blower
  861.   comment:
  862. '
  863. This is a Furnace Blower.
  864. '
  865. .
  866.  !
  867. "\TeXCommand
  868. \startClassSection{Summary}
  869. "!
  870.  
  871.  
  872. "
  873. ************* Class Methods Summary ************
  874.  
  875. ----Public----
  876. new
  877.  
  878.  
  879. *********** Instance Methods Summary ***********
  880.  
  881. ----Public----
  882. isAccelerating
  883. isOff
  884. isOn
  885. isSlowing
  886. release
  887. speed
  888. turnOff
  889. turnOn
  890.  
  891.   Dependency  
  892. update: who
  893. update: who with: detail
  894.  
  895.   Widget  
  896. initWindowSize           Tell the topWidget what size to open to 
  897. modelReleased: who
  898.      The top Pane lost a model for one of its subPanes.
  899.      The whole window should close. 
  900.  
  901. openView                 create a blower interface      
  902.  
  903. ----Private----
  904. atSpeedValue
  905. initialize
  906.  
  907. --UNSPECIFIED--
  908.  
  909.   Old  
  910. openViewOld
  911.  
  912. ***************** End Summary ******************
  913. "!
  914.  
  915.  
  916.  
  917. !Blower class methods !
  918.  
  919. new
  920.         <<Public>>
  921.  
  922.     ^super new initialize! !
  923.  
  924.  
  925. !Blower methods !
  926.  
  927. atSpeedValue
  928.         <<Private>>
  929.     ^120!
  930.  
  931. initialize
  932.         <<Private>>
  933.     | sim  |
  934.  
  935.     on := BooleanInformer new.
  936.     on toFalse.
  937.  
  938.     speed := IntervalInformer new.
  939.     speed min: 0 max: 300 precision: 1.
  940.     speed addDependent: self.
  941.  
  942.  
  943.     sim := BlowerSim new.
  944.  
  945.     internalModels := OrderedCollection with: sim.
  946.  
  947.     sim initChange: speed on: on
  948.            plus: 10 minus: 20 per: #fiveSecondEvent
  949.            atSpeed: (self atSpeedValue).!
  950.  
  951. initWindowSize
  952.         <<Public>><<Widget>>
  953.     "Tell the topWidget what size to open to"
  954.  
  955.     | listLineHeight halfLineHeight |
  956.     listLineHeight := Font menuFont height + 12.
  957.     halfLineHeight := Font menuFont height + 6.
  958.  
  959.     ^200@((3*listLineHeight) + (halfLineHeight*1))!
  960.  
  961. isAccelerating
  962.         <<Public>>
  963.  
  964.     ^on value & (self isOn not)!
  965.  
  966. isOff
  967.         <<Public>>
  968.  
  969.     ^speed value == 0!
  970.  
  971. isOn
  972.         <<Public>>
  973.  
  974.     ^speed value >= (self atSpeedValue)!
  975.  
  976. isSlowing
  977.         <<Public>>
  978.  
  979.     ^on value not & (self isOff not)!
  980.  
  981. modelReleased: who
  982.         <<Public>><<Widget>>
  983.     "The top Pane lost a model for one of its subPanes.
  984.      The whole window should close."
  985.  
  986.  
  987.     ^true!
  988.  
  989. openView
  990.         <<Public>><<Widget>>
  991.     "create a blower interface     "
  992.  
  993.  
  994.  
  995.     | listLineHeight aWidget aView
  996.          statusModel
  997.       topWidget min max
  998.       halfLineHeight
  999.     |
  1000.  
  1001.  
  1002.     CursorManager execute change.
  1003.  
  1004.     listLineHeight := Font menuFont height + 12.
  1005.     halfLineHeight := Font menuFont height + 6.
  1006.  
  1007.  
  1008.     topWidget := WTopWidget new
  1009.         "model: nil;"
  1010.         owner: self;
  1011.         label: 'Blower';
  1012.         yourself.
  1013.  
  1014.     topWidget := topWidget.
  1015.  
  1016.     topWidget  view minimumSize: 300 @ 200.
  1017.     topWidget  view whiteOnRedraw: true.
  1018.     topWidget  view windowType: Window noGrowDocProc.
  1019.  
  1020.  
  1021.  
  1022.  
  1023.     topWidget addSubWidget:
  1024.         ((aWidget := WLinearView newWidget)
  1025.             model: speed;
  1026.             owner: self).
  1027.     aView := aWidget view.
  1028.  
  1029.  
  1030.     min := speed min. max := speed max.
  1031.  
  1032.     aView
  1033. "           drawBorder: #thicktLine;  "
  1034.             framingBlock: [:box|
  1035.                 box origin + (0 @ (listLineHeight * 1))
  1036.                     extent:
  1037.                 box width @ (listLineHeight * 2 + halfLineHeight)];
  1038.             initLowReading:  min
  1039.                 highReading:  max
  1040.                 tickMarks: (( min to:  max by: 20) collect:
  1041.                     [:item | ((item - min) \\ 60 == 0) ifTrue: [
  1042.                         item printString] ifFalse: ['']
  1043.                 ])
  1044.                 subTicks: 1";
  1045.             extraBorder: 10".
  1046.  
  1047.  
  1048.  
  1049.     (statusModel := CalcValueInformer new)
  1050.         valueBlock: [:model |
  1051.             model value ifTrue: ['Blower on'] ifFalse: ['Blower off']];
  1052.         model: on.
  1053.  
  1054.  
  1055.  
  1056.     topWidget addSubWidget:
  1057.         ((aWidget := WStatusWidget new)
  1058.             setNilDecodeBlock;
  1059.             owner: self).
  1060.     aView := aWidget view.
  1061.  
  1062.     aView
  1063.             label: 'Blower Speed (RPM)';
  1064.            " drawBorder: #thickbLine;  "
  1065.             framingBlock: [:box|
  1066.                 box origin + (0 @ ((listLineHeight * 3)))
  1067.                     extent:
  1068.                 box width @ halfLineHeight];
  1069.             yourself.
  1070.  
  1071.  
  1072.     topWidget addSubWidget:
  1073.         ((aWidget := WStatusWidget new)
  1074.             modelText: statusModel boolean: on;
  1075.             owner: self).
  1076.     aView := aWidget view.
  1077.  
  1078.     aView
  1079.             drawBorder: #bLine;
  1080.             framingBlock: [:box|
  1081.                 box origin + (0 @ 0 )
  1082.                     extent:
  1083.                 box width @ listLineHeight];
  1084.             yourself.
  1085.  
  1086.  
  1087.     internalModels add: statusModel.
  1088.  
  1089. "                   add: topWidget"
  1090.  
  1091.     topWidget open.
  1092.     topWidget addWindow.!
  1093.  
  1094. openViewOld
  1095.         <<Old>>
  1096.     |simple topWidget|
  1097.  
  1098.     simple := (SimpleWidgetWindow new createSwitchOn: on).
  1099.     simple
  1100.         owner: self.
  1101.  
  1102.     topWidget := simple topWidget.
  1103.  
  1104.     topWidget label: 'Blower On'.
  1105.  
  1106.  
  1107.     topWidget view windowType: Window noGrowDocProc.
  1108.     "topWidget view closeable: false."
  1109.  
  1110.     topWidget open.
  1111.     topWidget addWindow.
  1112.  
  1113.  
  1114.     simple := (SimpleWidgetWindow new createDialOn: speed).
  1115.     simple
  1116.         owner: self.
  1117.  
  1118.     topWidget := simple topWidget.
  1119.  
  1120.     topWidget label: 'Blower speed'.
  1121.     simple mainWidget view
  1122.             initLowReading:  speed min
  1123.                 highReading:  speed max
  1124.                 startDegree: 100
  1125.                 rangeDegree: 340
  1126.                 tickMarks: ((speed min to: speed max by: 20) collect: [:item |  
  1127. item printString])
  1128.                 subTicks: 4.
  1129.  
  1130.     topWidget open.
  1131.     topWidget addWindow.!
  1132.  
  1133. release
  1134.         <<Public>>
  1135.  
  1136.     super release.
  1137.  
  1138.     internalModels isNil ifFalse: [
  1139.         internalModels do: [:each |
  1140.             each releaseFirst: self.
  1141.         ].
  1142.     ].
  1143.     internalModels := nil.
  1144.  
  1145.     on releaseFirst: self.
  1146.     on := nil.
  1147.  
  1148.     speed releaseFirst: self.
  1149.     speed := nil.!
  1150.  
  1151. speed
  1152.         <<Public>>
  1153.  
  1154.     ^speed value!
  1155.  
  1156. turnOff
  1157.         <<Public>>
  1158.  
  1159.     on toFalse!
  1160.  
  1161. turnOn
  1162.         <<Public>>
  1163.  
  1164.     on toTrue!
  1165.  
  1166. update: who
  1167.         <<Public>><<Dependency>>
  1168.  
  1169.     who == speed ifTrue: [
  1170.         ((speed value >= (self atSpeedValue)) and: [on value]) ifTrue: [
  1171.             self changedDetail: #atSpeed
  1172.         ].
  1173.         ((speed value == 0) and: [on value not]) ifTrue: [
  1174.             self changedDetail: #stopped
  1175.         ].
  1176.     ].!
  1177.  
  1178. update: who with: detail
  1179.         <<Public>><<Dependency>>
  1180.  
  1181.     detail == #release ifTrue: [
  1182.         self release.
  1183.         ^self
  1184.     ].
  1185.  
  1186.     self update: who.! !
  1187. "\TeXCommand
  1188. \startClassDef{Valve}{BooleanInformer}
  1189. \setVersion{1:48 on Oct  4, 1991}
  1190. \setHierarchy{{BooleanInformer}{Informer}{Object}}
  1191. \endClassDef
  1192. "!
  1193.  
  1194.  
  1195. BooleanInformer subclass: #Valve
  1196.   instanceVariableNames: ''
  1197.   classVariableNames: ''
  1198.   poolDictionaries: ''.
  1199.  
  1200. "\TeXCommand
  1201. \startClassSection{Comment}
  1202. "!
  1203.  
  1204.  
  1205. Valve
  1206.   comment:''
  1207. .
  1208.  !
  1209. "\TeXCommand
  1210. \startClassSection{Summary}
  1211. "!
  1212.  
  1213.  
  1214. "
  1215. ************* Class Methods Summary ************
  1216.  
  1217.  
  1218. *********** Instance Methods Summary ***********
  1219.  
  1220. --UNSPECIFIED--
  1221. close
  1222. open
  1223. printOn: aStream
  1224.      Append the ASCII representation of the receiver to
  1225.      aStream. 
  1226.  
  1227. valueText
  1228.  
  1229.  
  1230. ***************** End Summary ******************
  1231. "!
  1232.  
  1233.  
  1234.  
  1235. !Valve class methods ! !
  1236.  
  1237.  
  1238. !Valve methods !
  1239.  
  1240. close
  1241.     self toFalse!
  1242.  
  1243. open
  1244.     self toTrue!
  1245.  
  1246. printOn: aStream
  1247.     "Append the ASCII representation of the receiver to
  1248.      aStream."
  1249.  
  1250.     self class printOn: aStream.
  1251.     aStream nextPut: $(.
  1252.     aStream nextPutAll: self valueText.
  1253.     aStream nextPut: $).!
  1254.  
  1255. valueText
  1256.     ^value ifTrue: ['open'] ifFalse: ['closed']! !
  1257.